/** 
 * @desc   SVG转PNG
 * @param  {Object} obj 
 * @param  {Number} obj.scale 缩放
 * @param  {Number} obj.length 长度
 * @param  {String} obj.src 图片路径
 * @param  {Boolean} obj.base64 输出数据类型是否 base64
 * @param  {Function} obj.success 成功回调
 * @param  {Function} obj.error 失败回调
 */
function dealImage(obj) {
    var img = new Image();
    img.src = obj.src;
    img.onload = function () {
        // 默认按比例压缩
        var w = this.width,
            h = this.height,
            scale = w / h;
        if (obj.length) {
            if (w > h) {
                w = obj.length;
                h = (w / scale);
            } else {
                h = obj.length;
                w = (h * scale);
            }
        } else {
            w = obj.width || w;
            h = obj.height || (w / scale);
        }
        //生成canvas
        var canvas = document.createElement('canvas');
        var ctx = canvas.getContext('2d');
        canvas.width = w;
        canvas.height = h;
        ctx.drawImage(this, 0, 0, w, h);
        if (obj.success) {
            if (obj.base64) obj.success(canvas.toDataURL(obj.type || 'image/png'));
            else canvas.toBlob(obj.success);
        }
    };
    img.error = obj.error || function () { };
}
